<?php

declare(strict_types=1);

namespace App\Api\Service;

use App\Model\CarCategory;
use Hyperf\Contract\LengthAwarePaginatorInterface;

class CarCategoryService
{
    /**
     * 车辆分类列表
     * @return LengthAwarePaginatorInterface
     */
    public function index(): LengthAwarePaginatorInterface
    {
        // 查询
        $res = CarCategory::query()
            ->latest('weight')
            ->latest('id')
            ->paginate();

        // 组装数据
        /** @var CarCategory $model */
        foreach ($res as $model) {
            $model->setVisible(['id', 'name']);
        }

        return $res;
    }
}
